package ui.uea;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TableModelListener;
import javax.swing.table.JTableHeader;

import ui.component.FontPack;
import vo.ModelVO;

@SuppressWarnings("serial")
public class PlanPanel extends JPanel {
	private UEAPicturePath path = new UEAPicturePath();
//	x=260,y=91][x=945,y=538]
	private Rectangle frameworkRect = new Rectangle(60,91, 945 - 60, 538 - 91);
	private JScrollPane scrollPane;
	private FrameworkTable framework;
	private JTable frameworkTable;
	private TableModelListener frameworkTableListener;
	private List<ModelVO> models;
	public PlanPanel(){
		 framework  = new FrameworkTable();
		 frameworkTable = framework.getFrameworkTable();
		 
		this.setLayout(null);
		initScrollPane();
		this.add(scrollPane);

	}
	public TableModelListener getFrameworkTableListener() {
		return frameworkTableListener;
	}
	public void setFrameworkTableListener(TableModelListener frameworkTableListener) {
		this.frameworkTable.getModel().addTableModelListener(frameworkTableListener);
	}
	public List<ModelVO> getModels() {
		return models;
	}
	public JTable getFrameworkTable() {
		return frameworkTable;
	}
	public void fillFramework(List<ModelVO> models){
		framework.fillFramework(models);
	}

	private void initScrollPane(){
		setTableHeader();
		
		scrollPane = new JScrollPane(frameworkTable);
		scrollPane.setBounds(frameworkRect);
		scrollPane.getViewport().setOpaque(false);
		scrollPane.setOpaque(false);
		scrollPane.setBorder(new EmptyBorder(0,0,0,0));
	}
	private void setTableHeader(){
	JTableHeader header = frameworkTable.getTableHeader();
	header.setFont(FontPack.getModelFont(15));
	header.setBackground(Color.WHITE);
	header.setOpaque(false);
	header.setForeground(new Color(0,150,219));
	header.setBorder(new EmptyBorder(0,0,0,0));
}
	@Override
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		BufferedImage im = null;
		try {
			 im = ImageIO.read(new File(path.getPlanPanel()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		g.drawImage(im, 0, 0,this.getWidth(),this.getHeight(), null);
	}
}
